package game;


import java.util.ArrayList;
import java.util.Collections;

public class Deck {
	private final String[] suits = {"Spades","Diamonds","Clubs","Hearts"};
	private ArrayList<Card> deck;
	private final int shuffleTimes = 10;
	/**
	 * Creates a new deck and shuffels it.
	 */
	public Deck(){
		this.deck = genDeck();
		shuffleDeck();
	}
	
	private ArrayList<Card> genDeck() {
		ArrayList<Card> output = new ArrayList<Card>(52);
		for (int i = 0; i < suits.length; i++) {
			for (int k = 2; k < 15; k++) {
				output.add(new Card(suits[i], k));
			}
		}
		return output;
	}
	/**
	 * Shuffles current deck "shuffleTimes" times.
	 */
	public void shuffleDeck() {
		synchronized (deck) {
			for (int i = 0; i < shuffleTimes; i++) {
				Collections.shuffle(deck);
			}
		}
	}
	/**
	 * Returns first card from deck and removes it.
	 * @return first card in deck or null if there is no cards left.
	 */
	public Card takeCard() {
		synchronized (deck) {
			if (deck.size() == 0) {
				return null;
			} else {
				Card card = deck.get(0);
				deck.remove(card);
				return card;
			}
		}
	}
	/**
	 * @return the deck
	 */
	public ArrayList<Card> getDeck() {
		synchronized (deck) {
			return deck;
		}
	}
	
	
}
